package cn.yeamin.ms.mapper;

import java.util.Set;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import cn.yeamin.ms.vo.Role;
import tk.mybatis.mapper.common.Mapper;

/**
 * @packageName: 包名: cn.yeamin.ms.mapper
 * @classDesc: 类功能描述:()
 * @author: Administrator
 * @createTime: 2017/7/25 14:22
 * @version: v1.0
 * @copyright:奕明(上海)影视传媒有限公司
 */
public interface RoleMapper extends Mapper<Role> {

    @Select("SELECT tb_role.* FROM tb_user INNER JOIN tb_user_role ON tb_user.id = tb_user_role.user_id INNER JOIN tb_role ON tb_user_role.role_id = tb_role.id WHERE tb_user.id = #{id} AND tb_role.STATUS = 1")
    Set<Role> findRoleByUserId(Long id);

    @Insert("insert into tb_user_role values(#{userId},#{roleId})")
	void grant(@Param("userId") Long userId, @Param("roleId") Long roleId);

    @Delete("delete from tb_user_role where user_id = #{userId} AND role_id = #{roleId}")
	void deleteGrant(@Param("userId") Long userId, @Param("roleId") Long roleId);

    @Delete("delete from tb_user_role where user_id = #{userId}")
	void deleteAll(Long userId);


}
